package com.kayak.kboot.web.sys;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.WebApplicationContext;
import com.kayak.kboot.dao.SqlManager;

/**
 * 用于通过Spring框架静态取得定义好的bean对象实例
 */
public class SysBeans {
	private static Logger log = LoggerFactory.getLogger(SysBeans.class);

	private static WebApplicationContext currentApplicationContext = null;

	public static void setCurrentApplicationContext(WebApplicationContext currentApplicationContext) {
		SysBeans.currentApplicationContext = currentApplicationContext;
	}

	/**
	 * 静态获取bean实例
	 *
	 * @param beanId
	 * @return
	 */
	public static Object getBean(String beanId) {
		WebApplicationContext wc = ContextLoader
				.getCurrentWebApplicationContext();
		if (wc == null)
			wc = currentApplicationContext;
		//根据id获得bean
		return wc.getBean(beanId);
	}

	/**
	 * 取id=sysSql的bean实例<br />
	 * 系统SQL配置管理器
	 *
	 * @return
	 */
	public static SqlManager getSysSql() {
		return (SqlManager) getBean("sysSql");
	}

}
